/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package multi.agent.simulation;

import com.sun.org.apache.bcel.internal.generic.AALOAD;
import java.util.ArrayList;

/**
 *
 * @author Fernando
 */
public class BestRoadRequest {
    
    public String RequestID;
    public String DestinationName;
    public String RequesterName;   
    public int RequestCount;
    public int ReplyCount;
    public ArrayList<BestRoadReply> Replies;
    
    public BestRoadRequest() {
        Replies = new ArrayList<>();
    }
    
    public String toMessageString(){
        String msg = RequestID + ";" + DestinationName + ";" + RequesterName;
        return msg;
    }
    
    public BestRoadReply getBestReply(){
        BestRoadReply best = Replies.get(0);
        for (int i = 1; i < Replies.size(); i++){
            if (Replies.get(i).Weight < best.Weight){
                best = Replies.get(i);
            }
        }
        return best;
    }
    
    public static BestRoadRequest FromMessageString(String messageString) {
        BestRoadRequest brr = new BestRoadRequest();
        String[] split = messageString.split(";");
        brr.RequestID = split[0];
        brr.DestinationName = split[1];
        brr.RequesterName = split[2];
        return brr;
    }
}
